import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_api_path.dart';
import 'package:xindong/manager/network/xindong_networking.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/routes/common/xindong_help_yemian.dart';
import 'package:xindong/routes/common/xindong_web_html_yemian.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/container/xindong_empty_container.dart';
import 'package:xindong/widgets/xindong_common_select_item.dart';

class XinDongHelpNextYeMian extends StatefulWidget {
  final XinDongHelpClass model;

  const XinDongHelpNextYeMian({super.key, required this.model});

  @override
  State<XinDongHelpNextYeMian> createState() => _XinDongHelpNextYeMianState();
}

class _XinDongHelpNextYeMianState extends State<XinDongHelpNextYeMian> {
  List<XinDongHelpClass>? dataList;

  @override
  void initState() {
    super.initState();

    XinDongNetworking.instance.request(XinDongApi.helpQuestion, parameters: {"cid": widget.model.id}).then((value) {
      if (value.code == XinDongServerStatus.success) {
        List list = value.data;
        dataList = list.map((e) => XinDongHelpClass.fromJson(e)).toList();
      } else {
        dataList = [];
      }
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XinDongAppBar(widget.model.title),
      body: XinDongEmptyContainer(
        dataList: dataList,
        child: ListView.separated(
          itemCount: dataList?.length ?? 0,
          itemBuilder: (BuildContext context, int index) {
            XinDongHelpClass model = dataList![index];
            return XinDongCommonSelectItem(
              title: "${index + 1}、${model.title}",
              value: '',
              onTap: () {
                XinDongPageSingleton.instance.pushYeMian(XinDongWebHtmlYeMian(title: model.title, html: model.content));
              },
            );
          },
          separatorBuilder: (BuildContext context, int index) => const SizedBox(),
        ),
      ),
    );
  }
}
